package com.panshi.controller.qa;

import com.panshi.api.IQuestionApi;
import com.panshi.api.IRabbitMQApi;
import com.panshi.vo.qa.DataResultQA;
import com.panshi.vo.qa.Pages;
import com.panshi.vo.qa.Question;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@CrossOrigin//跨域
public class QuestionController {
    @Autowired
    IQuestionApi questionApi;

    @Autowired
    IRabbitMQApi rabbitMQApi;

    /*Question(问题)*/

    /**
     * 问题分页查询
     * @param pages
     * @return
     */
    @PostMapping("/question/inquirePages")
    @ResponseBody
    DataResultQA<Pages<Question>> inquirePagesQuestion(@RequestBody Pages pages){
        DataResultQA<Pages<Question>> dataResultQA= questionApi.inquirePagesQuestion(pages);
        return dataResultQA;
    }

    /**
     * 查询记录总数
     * @param pages
     * @return
     */
    @PostMapping("/inquireQuestionSum")
    @ResponseBody
    DataResultQA<Integer> inquireQuestionSum(@RequestBody Pages pages){
        DataResultQA<Integer> dataResultQA = questionApi.inquireQuestionSum(pages);
        return dataResultQA;
    }

    /**
     * 问题根据id查询
     * @param id
     * @return
     */
    @PostMapping("/question/inquireById/{id}")
    @ResponseBody
    DataResultQA<Question> inquireByIdQuestion(@PathVariable int id){
        DataResultQA<Question> dataResultQA = questionApi.inquireByIdQuestion(id);
        return dataResultQA;
    }

    /**
     * 问题收藏总数加一
     * @param id
     * @return
     */
    @GetMapping("/question/collectSumAnd1/{id}")
    @ResponseBody
    DataResultQA collectSumAnd1_Question(@PathVariable int id){
        DataResultQA dataResultQA = questionApi.collectSumAnd1_Question(id);
        return dataResultQA;
    }

    /**
     * 收藏总数减一
     * @param id
     * @return
     */
    @GetMapping("/question/collectSumSubtract1/{id}")
    @ResponseBody
    DataResultQA collectSumSubtract1(@PathVariable int id){
        DataResultQA dataResultQA = questionApi.collectSumSubtract1_Question(id);
        return dataResultQA;
    }

    /*//回答总数加一
    @GetMapping("/commentSumAnd1/{id}")
    @ResponseBody
    boolean commentSumAnd1(int id){
        boolean boo = qaApi.
        return boo;
    }*/

    /**
     * 回答总数减一
     * @param id
     * @return
     */
    @GetMapping("/question/commentSumSubtract1/{id}")
    @ResponseBody
    DataResultQA commentSumSubtract1(@PathVariable int id){
        DataResultQA dataResultQA = questionApi.commentSumSubtract1_Question(id);
        return dataResultQA;
    }

    /**
     * 问题标记删除
     * @param id
     * @return
     */
    @GetMapping("/question/delete/{id}")
    @ResponseBody
    DataResultQA deleteQuestion(@PathVariable int id){
        DataResultQA dataResultQA = questionApi.deleteQuestion(id);
        return dataResultQA;
    }

    /**
     * 用于用户查询自己发布的问题(分页查询)
     * @param pages
     * @return
     */
    @PostMapping("/question/inquireMyPagesQuestion")
    @ResponseBody
    DataResultQA<Pages<Question>> inquireMyPagesQuestion(@RequestBody Pages pages){
        DataResultQA<Pages<Question>> dataResultQA = questionApi.inquireMyPagesQuestion(pages);
        return dataResultQA;
    }

}
